package nina.yiyou.salary.output.util

import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.Sheet

class KeySheetReader {

  KeySheetReader(Sheet sheet) {
    _sheet = sheet
  }

  List<String> readKeys() {
    return getKeyCells().collect { new KeyCellReader(it).read() }
  }

  private List<Cell> getKeyCells() {
    int rowTotal = _sheet.lastRowNum + 1
    if (rowTotal == 1) {
      Row firstRow = _sheet.getRow(0)
      return (0..<firstRow.lastCellNum).collect { firstRow.getCell(it) }
    }
    return (0..<rowTotal).collect { _sheet.getRow(it).getCell(0) }
  }

  private final Sheet _sheet
}
